#pragma once

#include <string>
#include <grpc++/grpc++.h>
#include "response.hpp"
#include "v3/async/act_watch.hpp"


using etcdserverpb::KV;
using etcdserverpb::Watch;
using grpc::Channel;

namespace etcd {
class Watcher {
public:
    Watcher(std::string const& etcd_url, std::string const& key, std::function<void(const Response&)> callback);
    ~Watcher();
    void Cancel();
    void setStub(std::shared_ptr<Channel> channel);
    void doWatch(std::string const& key, std::function<void(const Response&)> callback);

protected:
    pplx::task<void> currentTask;
    std::unique_ptr<Watch::Stub> watchServiceStub;
    std::unique_ptr<etcdv3::AsyncWatchAction> call;
};

}
